package com.qidian.permission.controller;

import com.qidian.permission.entity.User;
import com.qidian.permission.service.UserService;
import com.qidian.permission.util.entity.PerResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Time 2023/10/18 10:20
 * @Description 这是一个测试
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @DeleteMapping("/{userId}")
    public PerResult deleteById(@PathVariable Long userId){
        return userService.deleteByUserId(userId);
    };

    @DeleteMapping("/deletes")
    public PerResult deletesById(Long [] userId){
        return userService.deletesByUserId(userId);
    };

    @PostMapping("/save")
    public PerResult save(@RequestBody User user){
        return userService.save(user);
    };

    @GetMapping("/get")
    public PerResult get(Long userId){
        return userService.queryById(userId);
    };

    @GetMapping("/list")
    public PerResult list(User user,@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int limit){
        return userService.queryByPage(user,page,limit);
    };

    @PutMapping("/update")
    public PerResult update(@RequestBody User user){
        return userService.update(user);
    };
}
